package com.huyn.baseframework.model;

import com.huyn.baseframework.utils.StringUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;

/**
 * Created by huyaonan on 16/8/31.
 */
public class VideoWithDefinitionModel implements Serializable {

    public int defaultdefinition;
    public List<String> definitionDescription;
    public List<VideoDefinition> definitions;

    public VideoDefinition getByIndex(int index) {
        if(definitions == null || index < 0 || index >= definitions.size())
            return null;
        return definitions.get(index);
    }

    public VideoDefinition getByDefinition(int definition) {
        if(definitions == null)
            return null;
        for(VideoDefinition item : definitions) {
            if(item.definition == definition && StringUtils.isNotBlank(item.playurl))
                return item;
        }
        return null;
    }

    public VideoDefinition getDefaultDefinition() {
        if(definitions == null)
            return null;
        for(VideoDefinition item : definitions) {
            if(item.definition == defaultdefinition && StringUtils.isNotBlank(item.playurl))
                return item;
        }
        return null;
    }

    public HashMap<Integer, String> getDefinitions() {
        HashMap<Integer, String> maps = new HashMap<>();
        if(definitions != null) {
            for(VideoDefinition definition : definitions) {
                maps.put(definition.definition, definition.desp);
            }
        }
        return maps;
    }

}
